#include "core/include/types.h"
#include "core/include/queue.h"

BOOL Enqueue(FIFO_BUF *buf, BYTE dat)
{
    BYTE r_ptr = buf->r_ptr;
    BYTE filledLen = QUEUE_FILLED_LENGTH(r_ptr, buf->w_ptr);

    if(filledLen != FIFO_BUF_SIZE)
    {
    	buf->buf[buf->w_ptr] = dat;
    	buf->w_ptr = (buf->w_ptr + 1) % FIFO_BUF_SIZE;

    	return TRUE;
    }
    else
    {
    	return FALSE;
    }
}

BOOL Dequeue(FIFO_BUF *buf, BYTE *dat)
{
    BYTE w_ptr = buf->w_ptr;
    BYTE filledLen = QUEUE_FILLED_LENGTH(buf->r_ptr, w_ptr);

    if(filledLen != 0)
    {
    	*dat = buf->buf[buf->r_ptr];
    	buf->r_ptr = (buf->r_ptr + 1) % FIFO_BUF_SIZE;

    	return TRUE;
    }
    else
    {
    	return FALSE;
    }
}

BOOL Init_FIFO_Buffer(FIFO_BUF *buf)
{
    buf->r_ptr = 0;
    buf->w_ptr = 0;

    return TRUE;
}

